package cc.sunwl.study.springboot.demo.gson.controller;

import cc.sunwl.study.springboot.demo.gson.entity.Article;
import cc.sunwl.study.springboot.demo.gson.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("demo/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @GetMapping("{id}")
    public Article get(@PathVariable String id) {
        return articleService.get(id);
    }

    @GetMapping
    public List<Article> get(@RequestParam(defaultValue = "1") int page,@RequestParam(defaultValue = "10") int size) {
        return articleService.findAll(page, size);
    }

    @PostMapping
    public boolean post(@RequestBody Article entity) {
        return articleService.post(entity);
    }

    @PutMapping
    public boolean put(@RequestBody Article entity) {
        return articleService.put(entity);
    }

    @DeleteMapping("{id}")
    public Boolean delete(@PathVariable String id) {
        return articleService.delete(id);
    }
}
